$(function() {

    $('#side-menu').metisMenu();

    var url = window.location;
    var element = $('ul.nav a').filter(function() {
        return this.href == url || url.href.indexOf(this.href) == 0;
    }).addClass('active').parent().parent().addClass('in').parent();
    if (element.is('li')) {
        element.addClass('active');
    }else{
    	var element2 = $('ul.nav a').filter(function() {
    		return this.href == url && this.href.length > 0;
    	}).addClass('active').parent().addClass('active');
    }
    
    $("#name_show").hover(function(){
    	$("#name_show .mr_edit").removeClass('hide');
    	$(this).addClass('resume-active');
    },function(){
    	$("#name_show .mr_edit").addClass('hide');
    	$(this).removeClass('resume-active');
    });
    $("#signature_show").hover(function(){
    	$("#signature_show .mr_edit").removeClass('hide');
    	$(this).addClass('resume-active');
    },function(){
    	$("#signature_show .mr_edit").addClass('hide');
    	$(this).removeClass('resume-active');
    });
    
    $('#moreinfo_show').hover(function(){
    	$("#moreinfo_show .mr_edit").removeClass('hide');
    	$(this).addClass('resume-active');
    },function(){
    	$("#moreinfo_show .mr_edit").addClass('hide');
    	$(this).removeClass('resume-active');
    });
    
    $("#checkUname").bind('input propertychange',function(){
    	var uname = $(this).val();
    	checkUsername('/member/check?uname='+uname,'error');
    });
    $(".resume-del-cancel").click(function(){
    	$(this).parent().parent().hide();
    })
    $(".ul_self_state li").click(function(){
    	//var token = $("#moreinfo_edit input[name=_token]").val();
    	var resume_status = $(this).text();
    	$.ajax({
    		'url':'/member/other',
    		'type':'POST',
    		'data':'&resume_status='+resume_status,
    		error: function(data) {
    			var response = data.responseJSON;
    			$.each(response,function(k,v){
    				errors +="<div>"+v+"</div>";
    			})
    			layer.open({title:'错误提示',content:errors});
            },
            success: function(data){
            	if(data.status == 'success'){
            		$('input[name=resume_status]').val(resume_status);
            	}
            },
    	})
    });
    $("#userlogoupload").click(function(){
    	$(this).parent().find('input').click();
    });
});

/**
 * 删除
 * @param url 删除路径
 * @param id 文章id
 * @param token 
 */
function delete_one(url,id){
    layer.confirm('确认删除',{title:'确定要删除吗?'},function(result){
            if(result) {
                $.ajax({
                    'url':url,
                    'type':'DELETE',
                    'data':'',
                    success: function(data){
                        if(data.status == 'success'){
                            layer.open({title:'提示',content:data.msg});
                            $("#news_"+id).remove();
                        }else{
                        	layer.open({title:'提示',content:data.msg});
                        }

                    },
                });
            }else{
            	layer.open({title:'提示',content:data.msg});
            }
        });
}
/**
 * 删除提示框
 * @param id
 */
function deleteAlert(id)
{
	$(id).parent().find('.delete-alter').show();
}
/**
 * 删除简历某条内容
 */
function deleteResume(app,url,appid)
{
	$.ajax({
		'url':url,
		'type':'DELETE',
		'data':"app="+app,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
        success: function(data){
			if(data.status == 'success'){

				$("#"+app+"_show_"+appid).remove();
				$("#"+app+"_edit_"+appid).remove();
                layer.msg(data.msg,{icon: 1});
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	})
}

/**
 * 保存简历
 */
function saveResume(url,formid,toshow){
	var data = $('#'+formid).serialize();
	var errors="";
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){
			if(data.status == 'success'){
				if(formid == 'name_edit'){
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow+" .userinfo-show").html(data.data.name);
				}
				else
				{
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow+" .userinfo-show").html(data.data.signature);
				}
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}

/**
 * 保存简历
 */
function saveUserInfo(url,formid,toshow){
	var form = $('#'+formid);
	var data = form.serialize();
	var errors="";
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){
			if(data.status == 'success'){
				$("#"+toshow).removeClass('hide');
				$("#"+formid).addClass('hide');
				var sexs="女";
				if(data.data.sex == 1){
					sexs = '男';
				}
				var html = '<div class="mb-10">'
		                +'<span class="mr_edit hide" onclick="resumeEdit(\'moreinfo_edit\',\'moreinfo_show\')"><i></i><em>编辑</em></span>'
		                +'<span  class="userinfo-show">'
		                	+'<img src="/images/front/member/home.jpg">'
		                	+'<span class="ml-10">'+data.data.shenfen+'</span>'
	                	+'</span>'
	                	+'</div>'
	                	+'<div class="mb-10">'
	                	+'  <span  class="userinfo-show">'
	                	+'      <img src="/images/front/member/data.jpg">'
	                	+'      <span class="ml-10">'
	                	+      sexs    +'&nbsp;&nbsp;'
	                	+      data.data.age    +'岁&nbsp;&nbsp;'
	                	+	   data.data.degree_i18n[data.data.highest_degree]  	+'&nbsp;&nbsp;'
	                	+	   data.data.gznx_i18n[data.data.gznx]  	+'&nbsp;工作经验&nbsp;'
	                	+'      </span>'
	                	+'  </span>'
	                	+'</div>'
	                	+'<div class="mb-10">'
	                	+'  <span  class="userinfo-show">'
	                	+'    <span class="ml-10">';
					if(data.data.tags){
	                    $.each(data.data.tags, function (ke, tag){
	                        if(ke<3){
	                            html    +=   '<span class="usertag">'+  tag.tags_name+'&nbsp;'+'</span>';
	                        }
	                    });
	                }
				    html    +='&nbsp;&nbsp;&nbsp;&nbsp;'
	                        +'      <i class="icon-map-marker"></i>&nbsp;'
		                	+		data.data.city_area.title +'-'+	data.data.province_area.title;
	                html    +='      </span>'
		                	+'  </span>'
		                	+'</div>';	
                   html +='<div class="mb-10">'
                        +'  <span  class="userinfo-show">'
                        +'      <img src="/images/front/member/call.jpg">'
                        +'      <span class="ml-10">'
                        +		data.data.phone	+'&nbsp;&nbsp;&nbsp;&nbsp;'
                        +'           <i class="icon-envelope"></i>&nbsp;'+data.data.email
                        +'      </span>'
                        +'  </span>'
                        +'</div>';

				$("#"+toshow).html(html);
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}

/**
 * 保存简历－工作经验
 */
function saveResumeExp(url,formid,toshow,type){
	var form = $('#'+formid);
	var data = form.serialize();
	var errors="";
	var clickVal = "";
	if(formid == 'add_new_experience') {
		clickVal = form.find('.resume-btn-ok').attr('onclick');
		form.find('.resume-btn-ok').attr('onclick','');
	}
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){
			if(data.status == 'success'){
				if(formid == 'add_new_experience') {
					form.get(0).reset();
					form.find('.resume-btn-ok').attr('onclick',clickVal);
				}
				var result = data.data;
				var htop = '<div class="mr_jobe_list" id="experience_show_'+result.id+'">';
				var html = '    <div class="clearfix">'
				       +'       <div class="mr_content_l">'
				       +'			<div class="l2">'
				       +'				<a class="projectTitle nourl">'+result.company_name+'</a>'
				       +'				<p>'+result.job+'</p>'
				       +'			</div>'
				       +'		</div>'
				       +'		<div class="mr_content_r">'
				       +'			<div class="mr_edit mr_c_r_t" onclick="resumeEdit(\'experience_edit_'+result.id+'\',\'experience_show_'+result.id+'\')">'
				       +'				<i></i><em>编辑</em>'
				       +'			</div>'
				       +'			<span>'+result.start_at+' - '+result.end_at+'</span>'
				       +'		</div>'
				       +'   </div>'
				       +'   <div class="mr_content_m">'
				       +	result.content    
				       +'	</div>';
				
				var hbom = '</div>';
				if(type == 'edit'){
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow).html(html);
				}
				else
				{
					html = htop+html+hbom;
					html+='<form class="hide" id="experience_edit_'+result.id+'">'

						+'       <input type="hidden" name="exp_id" value="'+result.id+'">'
						+'      <div class="mr_add_work">'
						+'          <div class="form-group clearfix">'
						+'              <label class="col-xs-12 col-sm-3 col-md-2 control-label">公司名称</label>'
						+'              <div class="col-sm-9 col-xs-12">'
						+'                  <input type="text" class="form-control" name="name" placeholder="公司名称" value="'+result.company_name+'">'
						+'              </div>'
						+'          </div>'
						+'          <div class="form-group clearfix">'
						+'              <label class="col-xs-12 col-sm-3 col-md-2 control-label">职位</label>'
						+'              <div class="col-sm-9 col-xs-12">'
						+'                  <input type="text" class="form-control" name="job" placeholder="职位" value="'+result.job+'">'
						+'              </div>'
						+'          </div>'
						+'          <div class="form-group clearfix">'
						+'              <label class="col-xs-12 col-sm-3 col-md-2 control-label">在职时间</label>'
						+'              <div class="col-sm-4 col-xs-12">'
						+'                  <input size="16" type="text" class="form_datetime date form-control" name="start_at" data-date-format="yyyy-mm" value="'+result.start_at+'" readonly>'
						+'              </div>'
						+'              <div class="col-sm-4 col-xs-12">'
						+'                  <input size="16" type="text" class="form_datetime input-append date form-control" name="end_at" data-date-format="yyyy-mm" value="'+result.end_at+'" readonly>'
						+'              </div>'
						+'          </div>'
						+'          <div class="form-group clearfix">'
						+'                <label class="col-xs-12 col-sm-3 col-md-2 control-label">工作内容</label>'
						+'              <div class="col-sm-9 col-xs-12">'
						+'                  <textarea name="content" id="content" class="content tex">'+result.content+'</textarea>'
						+'              </div>'
						+'          </div>'
						+'          <div class="form-inline mt-20">'
						+'              <div class="form-group">'
						+'                <span class="resume-btn-ok" onclick="saveResumeExp(\'/member/resume/experience\',\'experience_edit_'+result.id+'\',\'experience_show_'+result.id+'\',\'edit\')">'
						+'                      保存'
						+'                </span>'  
						+'              </div>'
						+'              <div class="form-group col-xs-offset-1">'
						+'                  <span class="resume-btn-cancel" onclick="resumeEdit(\'experience_edit_'+result.id+'\',\'experience_show_'+result.id+'\')">'
						+'                      取消'
						+'                  </span>'
						+'              </div>'
						+'              <div class="fr resume-delete">'
						  +'                <a href="javascript:void(0)" onclick="deleteAlert(this)"><span class="font-16 color-red2">删除本条</span></a>'
						  +'                <div class="delete-alter">'
						  +'                    <p>确定删除本条信息？</p>'
						  +'                    <div>'
						  +'						<span class="resume-del-ok" onclick="deleteResume(\'experience\',\'/member/resume/exp/'+result.id+'\',\''+result.id+'\')">删除</span>'
						  +'						<span class="resume-del-cancel">取消</span>'													
						  +'					</div>'
						  +'                </div>'
						  +'            </div>'
						+'          </div>'
						+'      </div>'
						+'  </form>';
//					$("#"+formid).reset();
					$("#"+formid).addClass('hide');
					$("#list_show_experience").append(html);
					editorInit();
				}
                layer.open({title:'提示',content:data.msg});
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}
/**
 * 保存简历 -教育经历
 */
function saveResumeEdu(url,formid,toshow,type){
	var form = $('#'+formid);
	var data = form.serialize();
	var errors="";
    var school = form.find('input[name=school]').val();
    var major = form.find('input[name=major]').val();
    if(!school||!major){
        layer.open({
            title:'系统提示',
            content:'学校专业不可为空！'
        });
        return false;
    }
    var clickVal = "";
	if(formid == 'add_new_educational') {
		clickVal = form.find('.resume-btn-ok').attr('onclick');
		form.find('.resume-btn-ok').attr('onclick','');
	}
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
            console.log("aa");
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){
			if(data.status == 'success'){
				if(formid == 'add_new_educational') {
					form.get(0).reset();
					form.find('.resume-btn-ok').attr('onclick',clickVal);
				}
				var result = data.data;
				var htop = '<div class="mr_jobe_list" id="educational_show_'+result.id+'">';
				var html = '<div class="clearfix">'
						   +'<div class="mr_content_l">'
						   +'		<div class="l2">'
						   +'			<a class="projectTitle nourl">'+result.school+'</a>'
						   +'			<p>'+result.degrees[result.degree]+' · '+result.major+'</p>'
						   +'		</div>'
						   +'	</div>'
						   +'	<div class="mr_content_r">'
						   +'		<div class="mr_edit mr_c_r_t" onclick="resumeEdit(\'educational_edit_'+result.id+'\',\'educational_show_'+result.id+'\')">'
						   +'			<i></i><em>编辑</em>'
						   +'		</div>'
						   +'		<span>'+result.graduated_at+'毕业</span>'
						   +'	</div>'
						   +' </div>'
			       var hbom = '</div>';
				if(type == 'edit'){
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow).html(html);
				}
				else
				{
					html = htop+html+hbom;
					var opt="";
					$.each(result.degrees,function(k,v){
						if(k == result.degree){
							opt += "<option value='"+k+"' selected>"+v+"</option>";
						}else{
							opt += "<option value='"+k+"'>"+v+"</option>";
						}
					});
					html+='<form class="hide" id="educational_edit_'+result.id+'">'

					      +'     <input type="hidden" name="edu_id" value="'+result.id+'">'
					      +'  <div class="mr_add_work">'
					      +'    <div class="form-group clearfix">'
					      +'        <label class="col-xs-12 col-sm-3 col-md-2 control-label">学校名称</label>'
					      +'        <div class="col-sm-9 col-xs-12">'
					      +'            <input type="text" class="form-control" name="school" placeholder="学校名称" value="'+result.school+'">'
					      +'        </div>'
					      +'    </div>'
					      +'    <div class="form-group clearfix">'
					      +'        <label class="col-xs-12 col-sm-3 col-md-2 control-label">所学专业</label>'
					      +'        <div class="col-sm-9 col-xs-12">'
					      +'            <input type="text" class="form-control" name="major" placeholder="所学专业" value="'+result.major+'">'
					      +'        </div>'
					      +'    </div>'
					      +'    <div class="form-group clearfix">'
					      +'        <label class="col-xs-12 col-sm-3 col-md-2 control-label">学历</label>'
					      +'        <div class="col-sm-9 col-xs-12">'
					      +'            <select class="form-control" name="degree">'
					      +	opt	
					      +'            </select>'
					      +'        </div>'
					      +'     </div>'
					      +'      <div class="form-group clearfix">'
					      +'         <label class="col-xs-12 col-sm-3 col-md-2 control-label">毕业时间</label>'
					      +'         <div class="col-sm-9 col-xs-12">'
					      +'            <input size="16" type="text" class="form_datetime2 input-append date form-control" name="graduated_at" data-date-format="yyyy-mm" value="'+result.graduated_at+'" readonly>'
					      +'        </div>'
					      +'    </div>'
					      +'    <div class="form-inline mt-20">'
					      +'        <div class="form-group">'
					      +'           <span class="resume-btn-ok"  onclick="saveResumeEdu(\'/member/resume/educational\',\'educational_edit_'+result.id+'\',\'educational_show_'+result.id+'\',\'edit\')">'
					      +'                保存'
					      +'           </span>'  
					      +'        </div>'
					      +'        <div class="form-group col-xs-offset-1">'
					      +'            <span class="resume-btn-cancel"  onclick="resumeEdit(\'educational_edit_'+result.id+'\',\'educational_show_'+result.id+'\')">'
					      +'                取消'
					      +'            </span>'
					      +'        </div>'
					      +'       <div class="fr resume-delete">'
					      +'        <a href="javascript:void(0)" onclick="deleteAlert(this)"><span class="font-16 color-red2">删除本条</span></a>'
					      +'        <div class="delete-alter">'
					      +'            <p>确定删除本条信息？</p>'
					      +'            <div>'
					      +'				<span class="resume-del-ok" onclick="deleteResume(\'educational\',\'/member/resume/edu/'+result.id+'\',\''+result.id+'\')">删除</span>'
					      +'				<span class="resume-del-cancel">取消</span>'													
					      +'			</div>'
					      +'        </div>'
					      +'       </div>'
					      +'    </div>'
					      +'</div>'
					      +'</form>';
					$("#"+formid).addClass('hide');
					$("#list_show_educational").append(html);
					editorInit();
				}
                layer.open({title:'提示',content:data.msg});
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}
/**
 * 保存简历-项目经验
 */
function saveResumePrj(url,formid,toshow,type){
	var form = $('#'+formid);
	var data = form.serialize();
	var errors="";
	var clickVal = "";
	if(formid == 'add_new_projects') {
		clickVal = form.find('.resume-btn-ok').attr('onclick');
		form.find('.resume-btn-ok').attr('onclick','');
	}
	//var tokens =$('input[name=_token]').val();
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){
			if(data.status == 'success'){
				if(formid == 'add_new_projects') {
					form.get(0).reset();
					form.find('.resume-btn-ok').attr('onclick',clickVal);
				}
				var res = data.data;
				var htop = '<div class="mr_jobe_list" id="projects_show_'+res.id+'">';
				var html = '<div class="clearfix">'
					       +'        <div class="mr_content_l">'
					       +'	<div class="l2">'
					       +'		<a class="projectTitle nourl">'+res.name+'</a>'
					       +'		<p>'+res.duty+'</p>'
					       +'	</div>'
					       +'	</div>'
					       +'	<div class="mr_content_r">'
					       +'	<div class="mr_edit mr_c_r_t" onclick="resumeEdit(\'projects_edit_'+res.id+'\',\'projects_show_'+res.id+'\')">'
					       +'		<i></i><em>编辑</em>'
					       +'	</div>'
					       +'	<span>'+res.start_at+' - '+res.end_at+'</span>'
					       +'</div>'
					       +'</div>'
					       +'<div class="mr_content_m">'
					       + res.intro
					       +'</div>';
				var hbom = '</div>';
				if(type == 'edit'){
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow).html(html);
				}
				else
				{
					html = htop + html + hbom;
					html+='<form class="hide" id="projects_edit_'+res.id+'">'
					      +'     <input type="hidden" name="prj_id" value="'+res.id+'">'
						  +'      <div class="mr_add_work">'
						  +'        <div class="form-group clearfix">'
						  +'            <label class="col-xs-12 col-sm-3 col-md-2 control-label">项目名称</label>'
						  +'            <div class="col-sm-9 col-xs-12">'
						  +'                <input type="text" class="form-control" name="name" placeholder="项目名称" value="'+res.name+'">'
						  +'            </div>'
						  +'        </div>'
						  +'        <div class="form-group clearfix">'
						  +'            <label class="col-xs-12 col-sm-3 col-md-2 control-label">你的职责</label>'
						  +'            <div class="col-sm-9 col-xs-12">'
						  +'                <input type="text" class="form-control" name="duty" placeholder="你的职责" value="'+res.duty+'">'
						  +'            </div>'
						  +'        </div>'
						  +'        <div class="form-group clearfix">'
						  +'            <label class="col-xs-12 col-sm-3 col-md-2 control-label">项目起止时间</label>'
						  +'            <div class="col-sm-4 col-xs-12">'
						  +'                <input size="16" type="text" class="form_datetime date form-control" name="start_at" data-date-format="yyyy-mm" value="'+res.start_at+'" readonly>'
						  +'            </div>'
						  +'            <div class="col-sm-4 col-xs-12">'
						  +'                <input size="16" type="text" class="form_datetime input-append date form-control" name="end_at" data-date-format="yyyy-mm" value="'+res.end_at+'" readonly>'
						  +'            </div>'
						  +'        </div>'
						  +'        <div class="form-group clearfix">'
						  +'            <label class="col-xs-12 col-sm-3 col-md-2 control-label">项目描述</label>'
						  +'            <div class="col-sm-9 col-xs-12">'
						  +'                  <textarea name="intro" id="content" class="tex content">'+res.intro+'</textarea>'
						  +'            </div>'
						  +'        </div>'
						  +'        <div class="form-inline mt-20">'
						  +'            <div class="form-group">'
						  +'              <span class="resume-btn-ok" onclick="saveResumePrj(\'/member/resume/projects\',\'projects_edit_'+res.id+'\',\'projects_show_'+res.id+'\',\'edit\')">'
						  +'                    保存'
						  +'              </span>'  
						  +'            </div>'
						  +'            <div class="form-group col-xs-offset-1">'
						  +'                <span class="resume-btn-cancel" onclick="resumeEdit(\'projects_edit_'+res.id+'\',\'projects_show_'+res.id+'\')">'
						  +'                    取消'
						  +'                </span>'
						  +'            </div>'
						  +'            <div class="fr resume-delete">'
						  +'                <a href="javascript:void(0)" onclick="deleteAlert(this)"><span class="font-16 color-red2">删除本条</span></a>'
						  +'                <div class="delete-alter">'
						  +'                    <p>确定删除本条信息？</p>'
						  +'                    <div>'
						  +'						<span class="resume-del-ok" onclick="deleteResume(\'projects\',\'/member/resume/proj/'+res.id+'\',\''+res.id+'\')">删除</span>'
						  +'						<span class="resume-del-cancel">取消</span>'													
						  +'					</div>'
						  +'                </div>'
						  +'            </div>'
						  +'        </div>'
						  +'    </div>'
						  +'</form>';
					$("#"+formid).addClass('hide');
					$("#list_show_projects").append(html);
					editorInit();
				}
                layer.open({title:'提示',content:data.msg});
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}

/**
 * 保存简历
 */
function saveResumeOther(url,formid,toshow){
	var data = $('#'+formid).serialize();
	var errors="";
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
		success: function(data){

			if(data.status == 'success'){
				if(formid == 'intro_edit'){
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow+" .self-intro-right").html(data.data.intro);
				}else{
					var html = '<li><i class="icon-user-md"></i>&nbsp;&nbsp;'+data.data.name+'</li>'
				        	   +'<li><i class="icon-time"></i>&nbsp;&nbsp;'+data.data.gzxz[data.data.job_type]+'</li>'
				        	   +'<li><i class="icon-map-marker"></i>&nbsp;&nbsp;'+data.data.cityname+'</li>'
				        	   +'<li><i class="icon-money"></i>&nbsp;&nbsp;'+data.data.salarys[data.data.expect_wages]+'</li>';
					$("#"+toshow).removeClass('hide');
					$("#"+formid).addClass('hide');
					$("#"+toshow+" ul").html(html);
				}
                layer.open({title:'系统提示',content:data.msg});
			}else{
				layer.open({title:'提示',content:data.msg});
			}

		},
	});
}

/**
 * 增加新的工作经历
 */
function resumeAdd(id){
	if($("#"+id).hasClass('hide')){
		$("#"+id).removeClass('hide');
	}else{
		$('#'+id).addClass('hide');
		
	}
		
}
/**
 * 编辑工作经历
 * @param id
 */
function resumeEdit(editId,showId){
	if($("#"+editId).hasClass('hide')){
		$("#"+editId).removeClass('hide');
		$("#"+showId).addClass('hide');
	}else{
		$("#"+editId).addClass('hide');
		$("#"+showId).removeClass('hide');
	}
}

/**
 * 职位地区，根据父分类获取子分类
 */
function childAreas(pid,uri,id){
	$.ajax({
		'url':'/'+uri,
		'type':'GET',
		'data':'pid='+pid,
		error: function(request) {
			$('#'+id).html('<option value="0">没有更多分类</option>');
        },
		success: function(data){
			if(data.status == 'success'){
				var result = data.data;
				var options ="";
				var firstid;
                if(result.length > 0){
                    $.each(result,function(k,e){
                    	if(k==0) firstid=e.area_id;
                        options +='<option value="'+e.area_id+'">'+e.title+'</option>';
                    });
                    if(id == 'city'){
                    	childAreas(firstid,uri,'area');
                    }
                    $('#'+id).html(options);
                }else{
    				$('#'+id).html('<option value="0">没有更多分类</option>');
    			}
			}else{
				$('#'+id).html('<option value="0">没有更多分类</option>');
			}
		},
	});
}

function checkUsername(url,id){
	$.ajax({
		'url':url,
		'type':'GET',
		'error':function(data){
			$("#"+id).html('网络异常！');
		},
		success:function(data){
			if(data.status == 'success'){
				$("#"+id).css("color","#006959");
				$("#"+id).html(data.msg);
			}else{
				$("#"+id).css("color","red");
				$("#"+id).html(data.msg);
			}
		}
	});
}

function toRead(url,divid){
	$.ajax({
		'url':url,
		'type':'GET',
		error: function(data) {
			layer.open({title:'提示',content:'没有更多数据'});
        },
        success: function(data){
			if(data.status == 'success'){
				var result = data.data;
				html="<tr><td>"
						+"<div class=\"form-group\"><span class=\"col-sm-4 col-xs-3 control-label\">用户:</span>"
							+"<div class=\"col-sm-5 col-xs-8\">"+result.username+"</div>"
						+"</div>"
					+"</tr></td>"
					+"<tr><td>"
						+"<div class=\"form-group\"><span class=\"col-sm-4 col-xs-3 control-label\">产生积分的动作:</span>"
							+"<div class=\"col-sm-5 col-xs-8\">"+result.action+"</div>"
						+"</div>"
					+"</tr></td>"
					/*+"<tr><td>"
						+"<div class=\"form-group\"><span class=\"col-sm-4 col-xs-3 control-label\">产生积分的URL:</span>"
							+"<div class=\"col-sm-5 col-xs-8\">"+result.action_url+"</div>"
						+"</div>"
					 +"</tr></td>"*/
					+"<tr><td>"
						+"<div class=\"form-group\"><span class=\"col-sm-4 col-xs-3 control-label\">积分值:</span>"
							+"<div class=\"col-sm-5 col-xs-8\">"+result.scores+"</div>"
						+"</div>"
					+"</tr></td>"
					+"<tr><td>"
						+"<div class=\"form-group\"><span class=\"col-sm-4 col-xs-3 control-label\">生成积分时间:</span>"
							+"<div class=\"col-sm-5 col-xs-8\">"+result.created_at+"</div>"
						+"</div>"
					+"</tr></td>";
				$("#showinfos").html(html);
				$("#" + divid + ">a").html('已查看');

				$('#myModal').modal();
			}else{
				layer.open({title:'提示',content:'没有更多数据'});
			}
        },
	});
}
/**
 * 消息详情
 */
function messageDetail(url,id)
{
	$.ajax({
		'url':url,
		'type':'GET',
		error: function(data) {
			layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
        	if(data.status == 'success')
        	{
        		var result = data.data;
        		var html = "";
        		$.each(result.data,function(k,v){
        			html += '<div class="talk_time">'+v.created_at+'</div>';
        			if(v.user_id != result.uid){
        				html += '<div class="ml-10 fl">'
	        						+'<img src="'+result.otherLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;">'
	        						+'<i class="glyphicon glyphicon-triangle-left" style="color:rgb(246,246,246);top:3px;left: -2px"></i>'
	        						+'<div class="talk_left_d word">'
	        						+'	<span class="talk_left_s">'+v.message+'</span>'
	        						+'</div>'
        						+'</div><div class="clearfix"></div>';
    				}else{
    					html += '<div class="mr-10 fr">'
		    						+'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
		    						+'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
		    						+'<div class="talk_right_d word">'
		    						+'	<span class="talk_right_s">'+v.message+'</span>'
		    						+'</div>'
								+'</div><div class="clearfix"></div>';
    				}
        		});
        		html +="<input type='hidden' name='rid' value='"+result.rid+"'><input type='hidden' name='id' value='"+result.id+"'>";
        		$('#myModalLabel').html(result.recipientname);
        		$('#messge_send').attr('onclick','sendMessage("/member/message","messageForm")');
        		$('#message_content').html(html);
        		$('#myMessageDetail').modal();
        		$('#unread_'+id).html(0);
        	}
        }
	});
}
/**
 * 发送消息
 */
function sendMessage(url,formid)
{
	var data = $('#'+formid).serialize();
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
        	if(data.status == 'success'){
        		var result = data.data;
        		var html = '<div class="talk_time">'+result.created_at+'</div>';
        		html += '<div class="mr-10 fr">'
							+'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
							+'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
							+'<div class="talk_right_d word">'
							+'	<span class="talk_right_s">'+result.message+'</span>'
							+'</div>'
						+'</div><div class="clearfix"></div>';
        		$("#message_content").append(html);
        		$("#msgContent").val('');
        	}
        	else
        	{
        		layer.open({title:'提示',content:data.msg});
        	}
        }
	});
}

/**
 * 简历状态改变
 * @param name
 */
function ChangeResumeStatus(name)
{
    $("input[name=resume_status]").val(name);
}
function logocrop(themid)
{
	if (!+[ 1, ]) {  
        createJCrop(1,themid);  
    } else {  
            //单独判断IE10  
        if (document.documentMode == 10) {  
            createJCrop(1);  
        } else  
        createJCrop(0,themid);  
    }  
	
}
var jcrop_api, boundx, boundy;
function createJCrop(flag,themid) 
{  
    if (flag == 0) {  
    	$('#'+themid).Jcrop({
            minSize: [80,80],
            setSelect: [0,0,80,80],
            aspectRatio: 1,
            onChange: updatePreview,
            onSelect: updateCoords
        },
        function(){
            var bounds = this.getBounds();
            boundx = bounds[0];
            boundy = bounds[1];
            jcrop_api = this;
        });  
    } else {  
        //IE下创建  
        var api = $.Jcrop('#'+themid, {
            minSize: [80,80],
            setSelect: [0,0,80,80],
            aspectRatio: 1,
            onChange: updatePreview,
            onSelect: updateCoords
        },
        function(){
            var bounds = this.getBounds();
            boundx = bounds[0];
            boundy = bounds[1];
            jcrop_api = this;
        });  
    }  
}
function updatePreview(c){
    if (parseInt(c.w) > 0)
    {
        var rx = 120 / c.w;
        var ry = 120 / c.h;
        $('#preview2').css({
            width: Math.round(rx * boundx) + 'px',
            height: Math.round(ry * boundy) + 'px',
            marginLeft: '-' + Math.round(rx * c.x) + 'px',
            marginTop: '-' + Math.round(ry * c.y) + 'px'
        });
    }
    
};
function updateCoords(c){
	var img = $('#target');
	var theImage = new Image();

	theImage.src = img.attr("src");
	var _w = img.width();
	var rw = theImage.width;
	var pop =  rw/_w;
    $('#x').val((c.x)*pop);
    $('#y').val((c.y)*pop);
    $('#w').val((c.w)*pop);
    $('#h').val((c.h)*pop);
};


/**
 * 查看用户简历
 */
function viewuserResume(url, data)
{
    $.ajax({
        'url': url,
        'type': 'GET',
        'data': data,
        error: function (data) {
            layer.open({title: '系统提示', content: '网络异常！'});
        },
        success:function(response){
            if(response.code == 0){
                var result = response.data;
                var html='';
                var experiences='';
                var educationals= '';
                var projects='';
                $.each(result.experiences,function(key,exp){
                    experiences +=  ' <div class="resume-content mr_w840" id="experience">'
                        +'     <div class="list_show" id="list_show_experience" >'
                        +'         <div class="mr_jobe_list">'
                        +'             <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+exp.company_name+'</a>'
                        +' 						<p>'+exp.job+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+exp.start_at+' - '+exp.end_at+'</span>'
                        +' 				</div>'
                        +'             </div>'
                        +'             <div class="mr_content_m">'
                        +				exp.content
                        +' 			</div>'
                        +'         </div>'
                        +'     </div>'
                        +' </div>';
                });
                $.each(result.educationals,function(ke,edu){
                    educationals +=' <div class="resume-content mr_w840">'
                        +'     <div class="list_show" id="list_show_educational" >'
                        +'         <div class="mr_jobe_list">'
                        +'             <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+edu.school+'</a>'
                        +' 						<p>'+result.degrees[edu.degree]+'· '+edu.major+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+edu.graduated_at+'年毕业</span>'
                        +'  				</div>'
                        +'             </div>'
                        +'         </div>'
                        +'     </div>'
                        +' </div>';
                });
                $.each(result.projects,function(k,prj){
                    projects += '<div class="mr_jobe_list">'
                        +'              <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+prj.name+'</a>'
                        +' 						<p>'+prj.duty+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+prj.start_at+' - '+prj.end_at+'</span>'
                        +' 				</div>'
                        +'             </div>'
                        +' 			<div class="mr_content_m">'
                        +				prj.intro
                        +' 			</div>'
                        +'         </div>';
                })
                var signature = '';
                if(result.signature != null && result.signature != undefined  )
                    signature = result.signature;
                html='<div class="resume-header">'
                    +'   	<img src="/images/front/member/bg.jpg">'
                    +'       <div class="resume-header-logo">'
                    +'           <img src="'+result.logo+'">'
                    +'     </div>'
                    +' </div>'
                    +' <div class="resume-userinfo">'
                    +'     <div class="resume-userinfo-title mr_w840 mb15">'
                    +'         <span  class="userinfo-show user-name">'+result.name+'</span>'
                    +'     </div>'
                    +'     <div class="resume-userinfo-center mr_w840 mb15">'
                    +'         <span  class="userinfo-show">'+signature+'</span>'
                    +'     </div>'
                    +'     <div class="resume-userinfo-center mr_w840">'
                    +'          <div class="mb10">'
                    +'             <span  class="userinfo-show">'
                    +'                 <img src="/images/front/member/data.jpg">'
                    +'                 <span class="ml10">'
                    +'                     '+result.sex+'&nbsp;&nbsp;'
                    +'                     '+result.age+'岁&nbsp;&nbsp;'
                    +'                     '+result.degrees[result.highest_degree]+'&nbsp;&nbsp;'
                    +                     	result.gznx+'年'
                    +'                 </span>'
                    +'             </span>'
                    +'         </div>';
                html    +='         <div class="mb10">'
                    +'             <span  class="userinfo-show">'
                        +'                 <span class="ml10">';
                        if(result.tags){
                            $.each(result.tags, function (ke, tag){
                                if(ke<3){
                                    html    +=   '<span class="usertag">'+  tag.tags_name+'&nbsp;'+'</span>';
                                }
                            });
                        }
                html    +='    &nbsp;&nbsp;&nbsp;&nbsp;'
                        +'      <i class="icon-map-marker"></i>'
                        +  result.city +'&nbsp;&nbsp;&nbsp;'
                        +  result.province 
                        +'                 </span>'
                        +'              </span>'
                        +'          </div>';         
           html     +='         <div class="mb10">'
                    +'             <span  class="userinfo-show">'
                    +'                 <img src="/images/front/member/call.jpg">'
                    +'                 <span class="ml10">'
                    +'                     '+result.phone+'&nbsp;&nbsp;&nbsp;&nbsp;'
                    +'                     <i class="icon-envelope"></i>&nbsp;'+result.email
                    +'                 </span>'
                    +'             </span>'
                    +'         </div>';

            html    +='     </div>'
                    +' </div>'
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">工作经历</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +	experiences
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">教育经历</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    + educationals
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">项目经验</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +' <div class="resume-content mr_w840">'
                    +'     <div class="list_show" id="list_show_projects" >'
                    +		projects
                    +'     </div>'
                    +' </div>'
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">自我描述</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +' <div class="resume-content mr_w840">'
                    +'    <div class="self_intro clearfix" id="intro_show">';

                if(result.intro != undefined && result.intro != null ){
                    html+= ' <div class="fl self-intro-right" id="other_insert">'
                        +			result.intro
                        +'         </div>';
                }
                html+='     </div>'
                    +' </div>';
                if(result.needs != undefined && result.needs != null ){
	                html+=' <div class="mr_moudle_head clearfix mr_w840">'
	                    +' 	<div class="fl">'
	                    +' 		<div class="mr_title">'
	                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">期望工作</span><span class="mr_title_r" style="width: 342px"></span>'
	                    +' 		</div>'
	                    +' 	</div>'
	                    +' </div>';
                    html+=' <div class="resume-content mr_w840">'
                        +'     <div class="list_show" >'
                        +'         <div class="mr_jobe_list clearfix" id="expect_show">'
                        +'         	<ul>'
                        +'         	   <li><i class="icon-user-md"></i>&nbsp;&nbsp;'+result.needs.name+'</li>'
                        +'         	   <li><i class="icon-time"></i>&nbsp;&nbsp;'+result.gzxzs[result.needs.job_type]+'</li>'
                        +'         	   <li><i class="icon-map-marker"></i>&nbsp;&nbsp;'+result.needs.cityname+'</li>'
                        +'         	   <li><i class="icon-money"></i>&nbsp;&nbsp;'+result.salarys[result.needs.expect_wages]+'</li>'
                        +'         	</ul>'
                        +'     	</div>'
                        +' 	</div>'
                        +'</div>';
                }
                if(result.resume_status != undefined && result.resume_status != null ){
                    html+= '<div class="mr_self_state company-center-form">'
                        +'	<div class="form_wrap">'
                        +'    <input id="resume_status" name="resume_status" type="button" style="height: 44px;" class="form-control"  value="'+result.resume_status+'">'
                        +'	</div>					'
                        +'</div>';
                }
                $('#myModalLabel').html(result.user.real_name);
                $('#resumebody').html(html);
                $('#myModal').modal();
            }else{
                layer.open({title:'系统提示',content:response.message});
            }
        }
    });
}


/**
 * 通用AJAX POST数据
 * @param string url  访问URL
 * @param object/string elem 传递参数
 * @param function fun
 */
function postRequest(url, elem, fun) {
    var data = '';
    if (typeof data === 'string')
        data = $('#' + elem).serialize();
    else if (typeof elem === 'object')
        data = elem;
    $.ajax({
        type: 'POST',
        url: url,
        data: data,
        success: function(data){
            if(data.status == 'success'){
                layer.open({title:'提示',content:data.msg});
                if ($.isFunction(fun)) {
                    fun();
                }
            }else{
                layer.open({title:'提示',content:data.msg});
            }

        },
    });
}